package cn.yunyichina.provider.base.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.fy.util.Record;
import com.fy.util.RecordSet;
import com.fy.util.db.CommonService;

import cn.yunyichina.provider.base.dao.ZhyySourceDao;
import cn.yunyichina.provider.framework.exception.CallException;
import cn.yunyichina.provider.iface.entity.ErrorCodeDefine;
import cn.yunyichina.utils.convert.JsonUtils;

/**
 * 订单表ord_order旧数据库同步到新数据库
 * @author adriftor
 *
 */
@Service("zhyyServiceImpl")
public class ZhyyServiceImpl extends CommonService {
	
	private static final Logger logger = LoggerFactory.getLogger(ZhyyServiceImpl.class);
	
	public RecordSet querySql(String sql) {

		ZhyySourceDao dao = null;
		try {
			logger.info("sql:"+sql);
			dao = new ZhyySourceDao();
			 if (sql.trim().startsWith("{")) {
				   JSONObject jsonObj = JsonUtils.parseObject(sql);
				   return dao.query(jsonObj.getString("sql"),new Record(jsonObj));
			  }
			  else {
				  return dao.query(sql);
			  }
			
		}
		catch(Exception ex) {
			logger.error(ErrorCodeDefine.ORDER_COMMON,"执行错误",ex);
			throw new CallException(ErrorCodeDefine.ORDER_COMMON,"执行错误",ex);
		}
		finally {
			try {
				if (dao != null) {
					dao.releaseCon();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	
	}
	
	
}
